<template>
    <div>
        <Row class="formRow">
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">订单编号</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.orderCode" placeholder="订单编号" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">客户名称</span>
          </Col>
          <Col span="2" class="leftRow">
           <Input v-model="formInline.userName" placeholder="客户名称" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">订单状态</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.state" placeholder="订单状态">
              <Option v-for="o in orderState"  :value="o.dataCode" :key="o.id">{{o.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle" style="width:100%">订单流程状态</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.processState" placeholder="订单流程状态">
              <Option v-for="p in processState"  :value="p.dataCode" :key="p.id">{{p.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
           <span class="ModelInputTitle" style="width:100%">提交开始时间</span>
          </Col>
          <Col span="2" class="leftRow">
            <DatePicker type="date" size="large" placeholder="提交开始时间" style="width:100%" v-model="formInline.submitStartTime"></DatePicker>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle" style="width:100%">提交结束时间</span>
          </Col>
          <Col span="2" class="leftRow">
            <DatePicker type="date" size="large" placeholder="提交结束时间" style="width:100%" v-model="formInline.submitEndTime"></DatePicker>
          </Col>
        </Row>
        <Row class="formRow" style="margin-top: 20px">
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">支付方式</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.paymentWay" placeholder="支付方式">
              <Option v-for="p in paymentWay"  :value="p.dataCode" :key="p.id">{{p.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">订单来源</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.orderSource" placeholder="订单来源">
              <Option v-for="o in orderSource"  :value="o.dataCode" :key="o.id">{{o.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">服务码</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.serviceCode" placeholder="服务码" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">医生姓名</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.doctorName" placeholder="医生姓名" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">科室</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.hospitalSubject" placeholder="科室">
              <Option v-for="h in hospitalSubject"  :value="h.dataCode" :key="h.id">{{h.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
          <span class="ModelInputTitle">医院名称</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.hospitalName" placeholder="医院名称" clearable style="width: 100%" size="large"></Input>
          </Col>
        </Row>
        <Row class="formRow" style="margin-top: 20px">
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">患者名称</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.patientName" placeholder="患者名称" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle">订单类型</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.orderType" placeholder="订单类型">
              <Option v-for="o in orderType"  :value="o.dataCode" :key="o.id">{{o.dataName}}</Option>
            </Select>
          </Col>
          <Col span="2" class="rightRow">
           <span class="ModelInputTitle">销售名称</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.saleName" placeholder="销售名称" clearable style="width: 100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
            <span class="ModelInputTitle" style="width: 100px">患者手机号</span>
          </Col>
          <Col span="2" class="leftRow">
            <Input v-model="formInline.phone" placeholder="患者手机号" clearable style="width:100%" size="large"></Input>
          </Col>
          <Col span="2" class="rightRow">
          <span class="ModelInputTitle">是否有效</span>
          </Col>
          <Col span="2" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.valid" placeholder="是否有效">
              <Option  value="1" >是</Option>
              <Option  value="0" >否</Option>
            </Select>
          </Col>
          <Col span="4" class="leftRow">
            <Button type="primary" @click="onSubmit">查询</Button>
            <Button type="primary" @click="resetForm">重置</Button>
          </Col>
        </Row>


      <Table :data="tableData" :columns="cloums" stripe :loading="loading"  style="margin-top: 20px"></Table>
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page :total="total" :current="1" :placement="placement" @on-change="changePage" show-total show-elevator show-sizer @on-page-size-change="changeSize"></Page>
        </div>
      </div>

      <Modal
        v-model="doctor"
        title="分配医院医生"
        @on-ok="doctorok"
        @on-cancel="cancel('您取消了操作')" width="600">
        <Row>
          <Col span="12">   <span class="ModelInputTitle">订单编号</span><Input size="large" v-model="doctorForm.orderCode" style="width: 200px" disabled></Input></Col>
          <Col span="12">   <span class="ModelInputTitle">提交时间</span><Input v-model="doctorForm.submitTime" size="large" style="width: 200px" disabled></Input></Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">客户(患者)名称</span><Input size="large" v-model="doctorForm.userName" style="width: 200px" disabled></Input></Col>
          <Col span="12">   <span class="ModelInputTitle">订单金额</span><Input v-model="doctorForm.amount" size="large" style="width: 200px" disabled></Input></Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">订单状态</span><Input size="large" v-model="doctorForm.state" style="width: 200px" disabled></Input></Col>
          <Col span="12">   <span class="ModelInputTitle">订单类型</span><Input v-model="doctorForm.orderType" size="large" style="width: 200px" disabled></Input></Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">患者身份证</span><Input size="large" v-model="doctorForm.idNumber" style="width: 200px" disabled></Input></Col>
          <Col span="12">   <span class="ModelInputTitle">患者年龄</span><Input v-model="doctorForm.age" size="large" style="width: 200px" disabled></Input></Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">患者性别</span><Input size="large" v-model="doctorForm.sex" style="width: 200px" disabled></Input></Col>
          <Col span="12">   <span class="ModelInputTitle">患者手机号</span><Input v-model="doctorForm.phone" size="large" style="width: 200px" disabled></Input></Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">分配医院</span>
          <Select  size="large" style="width:200px" v-model="doctorForm.hospital" placeholder="分配医院"  @on-change="doctorChange">
            <Option v-for="d in hospitalList"  :value="d.id" :key="d.hospitalCode">{{d.hospitalName}}</Option>
          </Select>
          </Col>
          <Col span="12">   <span class="ModelInputTitle">分配医生</span>
          <Select  size="large" style="width:200px" v-model="doctorForm.doctor" placeholder="分配医生">
            <Option v-for="t in doctorArr"  :value="t.id" :key="t.userCode">{{t.userName}}</Option>
          </Select>
          </Col>
        </Row>
        <Row style="margin-top: 20px">
          <Col span="12">   <span class="ModelInputTitle">科室</span>
          <Select  size="large" style="width:200px" v-model="doctorForm.sub" placeholder="科室">
            <Option v-for="t in hospitalSubject"  :value="t.dataCode" :key="t.id">{{t.dataName}}</Option>
          </Select>
          </Col>
        </Row>
      </Modal>

    </div>
</template>
<script type="text/ecmascript-6">
  import axios from "axios";
    export default {
        data() {
            return {
              page:1,
              pageSize:10,
              placement:"bottom",
              formInline: {
                submitStartTime:"",
                submitEndTime:"",
                valid:"",
                orderCode:"",//订单编号
                state:"",//订单状态
                userId:"",
                userName:"",//客户名称
                processState:"",//订单流程状态
                paymentWay:"",
                orderSource:"",//订单来源
                serviceCode:"",
                doctorName:"",
                hospitalSubject:"",
                hospitalName:"",
                patientName:"",
                saleName:"",
                orderType:"",
                name:"",
                phone:""
              },
              hospitalList:[],//医院列表
              orderState:[],//订单状态
              processState:[],//订单流程状态
              paymentWay:[],//支付方式
              orderSource:[],//订单来源
              hospitalSubject:[],//科室
              orderType:[],//订单类型
              tableData:[],
              loading:true,
              total:0,
              doctor:false,
              doctorArr:[],//分配医生
              doctorForm:{
                orderCode:"",
                submitTime:"",
                userName:"",
                amount:"",
                state:"",
                orderType:"",
                idNumber:"",
                age:"",
                sex:"",
                phone:"",
                doctor:"",
                hospital:"",
                sub:""
              },
              cloums:[
                {
                  title: '订单编号',
                  key: 'orderCode',
                  width:180,
                  align:"left"
                },
                {
                  title: '客户姓名',
                  key: 'userName',
                  width:150,
                  align:"center"
                },
                {
                  title: '患者姓名',
                  key: 'patientName',
                  width:150,
                  align:"center"
                },
                {
                  title: '患者身份证号',
                  key: 'idNumber',
                  width:180,
                  align:"center"
                },
                {
                  title: '患者出生年月',
                  key: 'dateBirth',
                  width:180,
                  align:"center"
                },
                {
                  title: '患者年龄',
                  key: 'age',
                  width:100,
                  align:"center"
                },
                {
                  title: '患者性别',
                  key: 'sex',
                  width:100,
                  align:"center"
                },
                {
                  title: '患者手机号',
                  key: 'phone',
                  width:150,
                  align:"center"
                },
                {
                  title: '订单金额',
                  key: 'amount',
                  width:120,
                  align:"center"
                },
                {
                  title: '支付方式',
                  key: 'paymentWay',
                  width:120,
                  align:"center"
                },
                {
                  title: '订单来源',
                  key: 'orderSource',
                  width:120,
                  align:"center"
                },
                {
                  title: '订单状态',
                  key: 'state',
                  width:120,
                  align:"center"
                },
                {
                  title: '订单流程状态',
                  key: 'processState',
                  width:150,
                  align:"center"
                },
                {
                  title: '服务码',
                  key: 'serviceCode',
                  width:150,
                  align:"center"
                },
                {
                  title: '医生姓名',
                  key: 'doctorName',
                  width:120,
                  align:"center"
                },
                {
                  title: '科室',
                  key: 'hospitalSubject',
                  width:100,
                  align:"center"
                },
                {
                  title: '医院名称',
                  key: 'hospitalName',
                  width:150,
                  align:"center"
                },
                {
                  title: '订单类型',
                  key: 'orderType',
                  width:120,
                  align:"center"
                },
                {
                  title: '销售人员',
                  key: 'saleName',
                  width:100,
                  align:"center"
                },
                {
                  title: '诊断',
                  key: 'diagnose',
                  width:180,
                  align:"center"
                },

                {
                  title: '是否有效',
                  key: 'valid',
                  width:100,
                  align:"center"
                },
                {
                  title: '创建人',
                  key: 'creater',
                  width:100,
                  align:"center"
                },
                {
                  title: '修改人',
                  key: 'updater',
                  width:100,
                  align:"center"
                },
                {
                  title: '提交时间',
                  key: 'submitTime',
                  width:150,
                  align:"center"
                },
                {
                  title: '操作',
                  width:180,
                  align:"center",
                  fixed:"right",
                  render:(h,params)=>{
                      return h("div",[
                        h("Button",{
                          props: {
                            type: 'error',
                            size: 'small'
                          },
                          style: {
                            marginRight: '5px'
                          },
                          on:{
                            click:()=>{
                              console.log(params.row)
                              if(params.row.state=="已预约"){
                                  this.doctorForm.orderCode = params.row.orderCode;
                                  this.doctorForm.submitTime = params.row.submitTime;
                                  this.doctorForm.userName = params.row.userName;
                                  this.doctorForm.amount = params.row.amount;
                                  this.doctorForm.state = params.row.state;
                                  this.doctorForm.orderType = params.row.orderType;
                                  this.doctorForm.idNumber = params.row.idNumber;
                                  this.doctorForm.age = params.row.age;
                                  this.doctorForm.sex = params.row.sex;
                                  this.doctorForm.phone = params.row.phone;
                                  this.doctor = true;
                              }else{
                                this.$Notice.error({title:"只能对已预约的订单分配医生"});
                              }
                            }
                          }
                        },"分配医生"),
                        h("Button",{
                          props: {
                            type: 'primary',
                            size: 'small'
                          },
                          style: {
                            marginRight: '5px'
                          },
                          on:{
                            click:()=>{
                              console.log(params.row)
                              this.$Notice.error({title:"接口没有"})
                            }
                          }
                        },"报告查询")
                      ])
                  }
                },
              ]
            }
        },
      mounted(){
          this.getInfo();
          this.init();
      },
      methods:{
        getInfo(){
          var _this = this;
          var qs = require("qs");
          axios.post("/order/selectHospitalList").then((res)=>{
            if(res.data.code =="000000"){
              _this.hospitalList = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })
          var orderState=[],processState=[],paymentWay=[],orderSource=[],hospitalSubject=[],orderType=[];

          var param = qs.stringify({
            dictType:"order_state"
          })
          axios.post("/common/dictDataList",param).then((res)=>{
            if(res.data.code =="000000"){
              _this.orderState = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })

          var param1 = qs.stringify({
            dictType:"order_processState"
          })
          axios.post("/common/dictDataList",param1).then((res)=>{
            if(res.data.code =="000000"){
              _this.processState = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })
          var param2 = qs.stringify({
            dictType:"payment_way"
          })
          axios.post("/common/dictDataList",param2).then((res)=>{
            if(res.data.code =="000000"){
              _this.paymentWay = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })

          var param3 = qs.stringify({
            dictType:"order_source"
          })
          axios.post("/common/dictDataList",param3).then((res)=>{
            if(res.data.code =="000000"){
              _this.orderSource = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })
          var param4 = qs.stringify({
            dictType:"hospital_subject"
          })
          axios.post("/common/dictDataList",param4).then((res)=>{
            if(res.data.code =="000000"){
              _this.hospitalSubject = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })
          var param5 = qs.stringify({
            dictType:"order_type"
          })
          axios.post("/common/dictDataList",param5).then((res)=>{
            if(res.data.code =="000000"){
              _this.orderType = res.data.data;
            }else{
              _this.$Notice.error({title:res.data.msg})
            }
          })

        },
        init(){
          var qs = require("qs");
          var param = qs.stringify({
            page:this.page,
            pageSize:this.pageSize,
            submitStartTime:this.formInline.submitStartTime,
            submitEndTime:this.formInline.submitEndTime,
            valid:this.formInline.valid,
            orderCode:this.formInline.orderCode,//订单编号
            state:this.formInline.state,//订单状态
            userId:this.formInline.userId,
            userName:this.formInline.userName,//客户名称
            processState:this.formInline.processState,//订单流程状态
            paymentWay:this.formInline.paymentWay,
            orderSource:this.formInline.orderSource,//订单来源
            serviceCode:this.formInline.serviceCode,
            doctorName:this.formInline.doctorName,
            hospitalSubject:this.formInline.hospitalSubject,
            hospitalName:this.formInline.hospitalName,
            patientName:this.formInline.patientName,
            saleName:this.formInline.saleName,
            orderType:this.formInline.orderType,
            name:this.formInline.name,
            phone:this.formInline.phone
          });

          axios.post("/order/selectOrderPage",param).then((res)=>{
            if(res.data.code == "000000"){
              this.loading = false;
              this.total = res.data.count;
              if(res.data.data==null){ this.tableData = [];return false;}
              for(let i=0;i<res.data.data.length;i++){
                res.data.data[i].valid = res.data.data[i].valid=="1"?"是":"否";
                if(res.data.data[i].sex==""||res.data.data[i].sex==null){
                  res.data.data[i].sex="";
                }else{
                  res.data.data[i].sex = res.data.data[i].sex=="1"?"男":"女";
                }
                res.data.data[i].submitTime = this.format(res.data.data[i].submitTime);
                res.data.data[i].dateBirth = this.format(res.data.data[i].dateBirth,"1");

                for(let j=0;j<this.orderState.length;j++){
                  if(res.data.data[i].state == this.orderState[j].dataCode){
                    res.data.data[i].state = this.orderState[j].dataName;
                  }
                }

                for(let j=0;j<this.processState.length;j++){
                  if(res.data.data[i].processState == this.processState[j].dataCode){
                    res.data.data[i].processState = this.processState[j].dataName;
                  }
                }

                for(let j=0;j<this.paymentWay.length;j++){
                  if(res.data.data[i].paymentWay == this.paymentWay[j].dataCode){
                    res.data.data[i].paymentWay = this.paymentWay[j].dataName;
                  }
                }

                for(let j=0;j<this.orderSource.length;j++){
                  if(res.data.data[i].orderSource == this.orderSource[j].dataCode){
                    res.data.data[i].orderSource = this.orderSource[j].dataName;
                  }
                }

                for(let j=0;j<this.hospitalSubject.length;j++){
                  if(res.data.data[i].hospitalSubject == this.hospitalSubject[j].dataCode){
                    res.data.data[i].hospitalSubject = this.hospitalSubject[j].dataName;
                  }
                }

                for(let j=0;j<this.orderType.length;j++){
                  if(res.data.data[i].orderType == this.orderType[j].dataCode){
                    res.data.data[i].orderType = this.orderType[j].dataName;
                  }
                }
              }
              this.tableData = res.data.data;
            }else{
              this.$Notice.error({title:res.data.msg})
            }
          })
        },
        onSubmit(){
          this.init();
        },
        resetForm(){
            this.formInline.submitStartTime = "";
            this.formInline.submitEndTime = "";
            this.formInline.valid = "";
            this.formInline.orderCode = "";//订单编号
            this.formInline.state = "";//订单状态
            this.formInline.userId = "";
            this.formInline.userName = "";//客户名称
            this.formInline.processState = "";//订单流程状态
            this.formInline.paymentWay = "";
            this.formInline.orderSource = "";//订单来源
            this.formInline.serviceCode = "";
            this.formInline.doctorName = "";
            this.formInline.hospitalSubject = "";
            this.formInline.hospitalName = "";
            this.formInline.patientName = "";
            this.formInline.saleName = "";
            this.formInline.orderType = "";
            this.formInline.name = "";
            this.formInline.phone = "";
            this.page = 1;
            this.pageSize = 10;
            this.init();
        },
        changePage(page){
          this.page = page;
          this.loading = true;
          this.init();
        },
        changeSize(size){
          this.placement = size>=20?"top":"bottom";
          this.pageSize = size;
          this.loading = true;
          this.init();
        },
        format(date,flag){
          if(date==""||date==null){
            return "";
          }
          var d = new Date(date);
          var year = d.getFullYear();
          var month = parseInt(d.getMonth())+1>9?parseInt(d.getMonth())+1:"0"+(parseInt(d.getMonth())+1);
          var day = d.getDate()>9?d.getDate():"0"+d.getDate();
          var h = d.getHours()>9?d.getHours():"0"+d.getHours();
          var m =  d.getMinutes()>9?d.getMinutes():"0"+d.getMinutes();
          var s = d.getSeconds()>9?d.getSeconds():"0"+d.getSeconds();

          if(flag =="1"){
            return year+"-"+month+"-"+day;
          }else{
            return year+"-"+month+"-"+day+" "+h+":"+m+":"+s;
          }

        },
        cancel (msg) {
          this.$Notice.info({title:msg});
        },
        doctorChange(c){
          var qs = require("qs");
          var param = qs.stringify({
            hospitalId:c
          })
          axios.post("/order/selectHospitalDoctorList",param).then((res)=>{
            if(res.data.code == "000000"){
              this.doctorArr = res.data.data;
            }else{
              this.$Notice.error({title:res.data.msg})
            }
          })
        },
        doctorok(){
          var qs = require("qs");
          var param = qs.stringify({
            orderCode:this.doctorForm.orderCode,
            doctorId:this.doctorForm.doctor,
            hospitalId:this.doctorForm.hospital,
            hospitalSubject:this.doctorForm.sub
          })
          axios.post("/order/updateOrderByPc",param).then((res)=>{
            if(res.data.code == "000000"){
              this.$Notice.success({title:"分配成功"});
              this.init();
            }else{
              this.$Notice.error({title:res.data.msg})
            }
          })
        }
      }
    }
</script>
